package android.cs2340UDT;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
 
public class CreateAccountActivity extends Activity {
	
	private Security security;
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
    	security = CS2340AndroidUDTActivity.getSecurity();
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.createaccount);
        
        Button CreateAccountButton = (Button) findViewById(R.id.CreateAccountButton);
        
        // gets all the UI edit text objects to retrieve user input text from
        final EditText inputName = (EditText) findViewById(R.id.name);
        final EditText inputUsername = (EditText) findViewById(R.id.username);
        final EditText inputDateOfBirth1 = (EditText) findViewById(R.id.dob1);
        final EditText inputDateOfBirth2 = (EditText) findViewById(R.id.dob2);
        final EditText inputDateOfBirth3 = (EditText) findViewById(R.id.dob3);
        final EditText inputPassword = (EditText) findViewById(R.id.password);
        final EditText inputConfirmPassword = (EditText) findViewById(R.id.confirmPassword);
 
        // Binding Click event to Button
        CreateAccountButton.setOnClickListener(new View.OnClickListener() {
 
            public void onClick(View arg0) {
            	// retrieves all the user input text 
            	String name = inputName.getText().toString();
            	String username = inputUsername.getText().toString();
            	String dateOfBirth = inputDateOfBirth1.getText().toString().concat(inputDateOfBirth2.getText().toString().concat(inputDateOfBirth3.getText().toString()));
            	String password = inputPassword.getText().toString();
            	String confirmPassword = inputConfirmPassword.getText().toString();
            	
            	// check to see if entries are valid
            	if(security.checkAccountEntries(name, username, password, confirmPassword, "", dateOfBirth)) {
            		// creates new user with entries
            		security.createUser(name, username, password, "", dateOfBirth);
            	}
            	
            	
                //Closing SecondScreen Activity
                finish();
            }
        });
 
    }
}

